home *** CD-ROM | disk | FTP | other *** search
/ L' Effet Pommier 3 / L'Effet Pommier - Volume 03.iso / Communication / I-Spy scripts / Sort file.pl < prev   
Perl Script  |  1995-12-23  |  868b  |  34 lines

  1. #!/usr/bin/perl
  2.  
  3. #    Sort file.pl
  4. #        This script sorts lines of a file
  5. #
  6. #        12/22/95 Version 1.0
  7. #        This script is free, public domain, no strings attached.
  8. #     Igor Livshits <igorl@uiuc.edu>
  9. #
  10. # Caveat: MacPerl will require much memory to sort large files: 3MB for InfoMac
  11.  
  12.  
  13. $openToWrite=                "> ";
  14. $macPathDelimiter=    ":";
  15.  
  16. #    Read in the arguments passed to us from the AppleScript agent
  17. #
  18. $workingDirectory=  $ARGV[$argumentCounter++] . $macPathDelimiter;
  19. $aFile=                          $ARGV[$argumentCounter++];
  20.  
  21.  
  22. # Read the file into an array
  23. #
  24. open(aFile, $workingDirectory . $aFile) || die "Cannot open $aFile: $!";
  25. @anArray= <aFile>;                    # read our file, line by line, into array elements
  26. close(aFile);
  27.  
  28.  
  29. # Dump the sorted array into our file
  30. #
  31. open(aFile, $openToWrite . $workingDirectory . $aFile) || die "Cannot open $aFile: $!";
  32. print (aFile (sort (@anArray)));
  33. close(aFile);
  34.